package com.dqlp.yf.rabbitmq.receive;

import com.dqlp.yf.rabbitmq.constant.MqConstant;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @program: rabbitmq
 * @description:
 * @author: andy
 * @create: 2019-09-09 14:14
 */
@Component
@Slf4j
public class LazyCustomer {
    @RabbitListener(queues = MqConstant.LAZY_QUEUE)
    public void lazyCustomer(Message message, Channel channel) {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        System.err.println("body: " + new String(message.getBody()));
        try {
            channel.basicAck(deliveryTag,false);
        } catch (IOException e) {
            try {
                channel.basicNack(deliveryTag,false,false);
            } catch (IOException e1) {
                log.info("失败");
            }
        }
    }
}
